@echo off & color 0A
pushd %cd%
cd  %~dp0

::指定起始文件夹
set DIR=%cd%\..\output\Package
echo 当前工作路径:%DIR%

:: 要删除的文件夹

set DEL_DIR_LEN=5
set DEL_DIR[0]=conf
set DEL_DIR[1]=Log
set DEL_DIR[2]=machine
set DEL_DIR[3]=script
set DEL_DIR[4]=dmp

if exist %DIR%\config.xml (del /q %DIR%\config.xml)
if exist %DIR%\user.json (del /q %DIR%\user.json)
if exist %DIR%\record.db (del /q %DIR%\record.db)

for /R %DIR% %%f in (*.iobj,*.ipdb,*.pdb,*.ilk,*.exp,*.lib) do (
    echo %%f
    del /q %%f 
)


for /f %%i in ('dir %DIR% /AD /B') do (
    call :func_search %%i %DIR%
)

echo 处理完成
goto :END

:func_search
    set str_find=%1
    set base_dir=%2
    set del_index=0
    :LoopStart
    if %del_index% equ %DEL_DIR_LEN% goto LoopStop
    for /F "usebackq delims== tokens=2" %%g in (`SET DEL_DIR[%del_index%]`) do (
        if '%str_find%' equ '%%g' (
			::set del_dir_name="%2"    
			echo 删除文件夹:%str_find%       
			rd /s /q "%2\%str_find%"
            
            goto LoopStop
        )
    )

    set /a del_index=%del_index% + 1
    goto LoopStart
    :LoopStop

	GOTO:EOF

:END
popd